package com.enation.app.shop.front.policyInsurance.service.impl;

import com.enation.app.shop.front.policyInsurance.entity.SysArea;
import com.enation.app.shop.front.policyInsurance.service.ISysAreaMapper;
import com.enation.framework.database.IDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("sysAreaService")
public class SysAreaService implements ISysAreaMapper {
    @Autowired
    private IDaoSupport daoSupport;
    @Override
    public List<SysArea> getByAreaLevel(Integer level) {
        String sql="select * from sys_area where area_level=?";
        return this.daoSupport.queryForList(sql,SysArea.class,level);
    }

    @Override
    public List<SysArea> getByLevelAndPidAndCid(Integer level, Integer pid, Integer cid) {
        String sql="";
        if (cid==null){
             sql="select * from sys_area where area_level=? and province_id=? ";
            return this.daoSupport.queryForList(sql,SysArea.class,level,pid);
        }else {
             sql="select * from sys_area where area_level=? and province_id=? and city_id=?";
            return this.daoSupport.queryForList(sql,SysArea.class,level,pid,cid);
        }
    }

    @Override
    public SysArea getByAreaCode(String id) {
        String sql="select * from sys_area where area_code=?";
        return this.daoSupport.queryForObject(sql,SysArea.class,id);
    }

    @Override
    public List<SysArea> getByLevelAndSidAndTid(Integer level, Integer province_id, Integer city_id,Integer region_id, Integer Streetid) {
        String sql="";
        if (Streetid==null){
            sql="select * from sys_area where area_level=? and province_id=? and city_id=?   and region_id=?";
            return this.daoSupport.queryForList(sql,SysArea.class,level,province_id,city_id,region_id);
        }else {
            sql="select * from sys_area where area_level=? and province_id=? and city_id=? and region_id=? and street_id=? ";
            return this.daoSupport.queryForList(sql,SysArea.class,level,province_id,city_id,region_id,Streetid);
        }

    }
}
